package com.karateca.columbiaimports.io;

import java.io.BufferedReader;
import java.io.FileReader;

/**
 * This class contains methods to read text files.
 * @author Andres Dominguez
 */
public class TextFileReader
{
    /**
     * Read a text file and return its contents as a string.
     * @param file file path.
     * @return a string with the contents of the file.
     * @throws java.lang.Exception in case of error.
     */
    public static String readFile(String file) throws Exception
    {
        StringBuilder sb = new StringBuilder();
        FileReader fileReader = new FileReader(file);

        BufferedReader br = new BufferedReader(fileReader);
        String line = br.readLine();
        while (line != null)
        {
            sb.append(line);
            line = br.readLine();
        }
        br.close();
        return sb.toString();
    }
}
